package middle

import (
	"bytes"
	"fmt"
	"github.com/gin-gonic/gin"
)

func Gzip() gin.HandlerFunc {
	return func(ctx *gin.Context) {

		if ctx.Request.Header.Get("Content-Encoding") == "gzip" {
			ctx.Header("Content-Encoding", "gzip")
			ctx.Header("Vary", "Accept-Encoding")
			writer := responseBodyWriter{
				ResponseWriter: ctx.Writer,
				body:           &bytes.Buffer{},
			}
			ctx.Writer = writer
			defer func() {
				ctx.Header("Content-Length", fmt.Sprint(ctx.Writer.Size()))
			}()
		}
		ctx.Next()

	}
}

//11=》22=> xxx
//11《==22==
